-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rust-sdk position test #601
base: main
Are you sure you want to change the base?
Conversation
let ctx = RpcContext::new().await; | ||
|
||
// Use token utility functions | ||
let position_mint = setup_mint_with_decimals(&ctx, 0).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to setup mint and ata when opening a position. The OpenPosition instruction will do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use OpenPosition ones!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just need to derive the address and not actually set up the accounts yet. OpenPosition instruction will try to set up the accounts and if they are already set up it fails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah understand what you mean. remove not to setup those things
rust-sdk/whirlpool/src/position.rs
Outdated
setup_ata_with_amount(&ctx, mint_b, 1_000_000_000).await?; | ||
|
||
let whirlpool = setup_whirlpool(&ctx, mint_a, mint_b, 64).await?; | ||
let position_pubkey = setup_position(whirlpool).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nice to add a position bundle and te_position as well to check if fetch_positions_for_owner
finds those positions as well.
Same goes from the fetch_positions_in_pool
test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added both to check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it still only sets up the normal postion. Did you forget to commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, updated now
…dk-add-position-test
…whirlpools into paul/rust-sdk-add-position-test
pub async fn setup_position(whirlpool: Pubkey) -> Result<Pubkey, Box<dyn Error>> { | ||
let ctx = RpcContext::new().await; | ||
|
||
let (position_pubkey, position_bump) = get_position_address(&Pubkey::new_unique())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now the position_pubkey gets derived from a different mint than you supply in the OpenPosition instruction (which will result in a constraint violation).
In order to fix this:
let position_mint = ctx.get_next_keypair();
let (position_pubkey, position_bump) = get_position_address(& position_mint.pubkey())?;
...
ctx.send_transaction_with_signers(vec![open_position_ix], vec![position_mint]).await?;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, updated pattern to use this pattern
pub async fn setup_te_position(whirlpool: Pubkey) -> Result<Pubkey, Box<dyn Error>> { | ||
let ctx = RpcContext::new().await; | ||
|
||
let position_mint = Keypair::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for the TE position as above. You don't have to init the mint and ata for the position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
||
// Use token utility functions | ||
let position_bundle_mint = setup_mint_with_decimals(&ctx, 0).await?; | ||
let position_bundle_token_account = setup_ata(&ctx, position_bundle_mint).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the same here. No need to init the mint and ata as InitializePositionBundle will do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
position_mint: Pubkey::new_unique(), | ||
position_token_account: Pubkey::default(), | ||
position_mint: position_mint.pubkey(), | ||
position_token_account: Pubkey::default(), // instruction will create |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instruction will initiate the account but you still need to provide the correct address for position_token_account
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
whirlpool, | ||
token_program: TOKEN_PROGRAM_ID, | ||
token_program: TOKEN_PROGRAM_ID, // or TOKEN_2022_PROGRAM_ID if needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TOKEN_2022_PROGRAM_ID is only for TE positions so irrelevant here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
let (position_pubkey, position_bump) = get_position_address(&te_position_mint.pubkey())?; | ||
|
||
// 3) Build an OpenPosition instruction with token_program = TOKEN_2022_PROGRAM_ID | ||
let position_token_account = get_associated_token_address_with_program_id( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one more for position bundle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, updated
Add Position and Position Bundle Test Coverage
Overview
Changes
setup_position
andsetup_position_bundle
for SPL and Token-2022.Notes
#[ignore]
due to missinggetProgramAccounts
support in solana-bankrun.#[ignore]
attributes.